package org.redis.cluster.test.config;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.redis.cluster.config.ConfigLoader;
import org.redis.cluster.config.RegistryConfig;
import org.redis.cluster.config.ServerConfig;
import org.redis.cluster.config.SystemConfig;
import org.redis.cluster.config.XmlConfigLoader;

public class ConfigLoaderTester_1 {
	
	private ConfigLoader configLoader;

	@Before
	public void before() {
		this.configLoader=initConfigLoader();
	}
	
	protected ConfigLoader initConfigLoader() {
		XmlConfigLoader xmlConfigLoader=new XmlConfigLoader();
		xmlConfigLoader.setConfig("server-test.xml");
		return xmlConfigLoader;
	}
	
	@Test
	public void test() {
		ServerConfig serverConfig=configLoader.loadServerConfig();
		RegistryConfig registryConfig=configLoader.loadRegistryConfig();
		SystemConfig systemConfig=configLoader.loadSystemConfig();
		
		Assert.assertEquals("netty",serverConfig.getServer());
		Assert.assertEquals(6379,serverConfig.getPort().intValue());
		Assert.assertEquals(8,serverConfig.getThread().intValue());
		Assert.assertEquals(10240,serverConfig.getBufferSize().intValue());
		Assert.assertEquals(3000,serverConfig.getTimeout().intValue());
		
		Assert.assertEquals("zookeeper",registryConfig.getRegistry());
		Assert.assertEquals("127.0.0.1:2181",registryConfig.getHost());
		Assert.assertEquals(2181,registryConfig.getPort().intValue());
		Assert.assertEquals(1000,registryConfig.getTimeout().intValue());
		Assert.assertEquals("/redis-cluster",registryConfig.getRoot());
		
		Assert.assertEquals("system_test_1_value", systemConfig.get("system_test_1").getValue());
		Assert.assertEquals("system_test_2_value", systemConfig.get("system_test_2").getValue());
		Assert.assertEquals("default_value", systemConfig.get("system_test_3").getValue(String.class,"default_value"));
	}
}